package com.nuanshui.heatedloan.credit.service;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.constant.DubboCacheRegion;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.credit.constant.HomePageConstant;
import com.nuanshui.heatedloan.credit.dal.mapper.ProductInfoMapper;
import com.nuanshui.heatedloan.credit.facade.CustomerProduceService;
import com.nuanshui.heatedloan.credit.model.LightLoanProductInfo;
import com.nuanshui.heatedloan.credit.model.ProductInfo;
import com.nuanshui.heatedloan.credit.model.SingleLoanProductInfo;
import com.nuanshui.heatedloan.dubbo.extension.cache.manager.DubboCacheManager;
import com.nuanshui.heatedloan.model.Image;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangxw on 2017/7/12.
 */

@Service(ServiceConstant.CUSTOMERPRODUCESERVICE)
@Transactional(readOnly=true,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
public class CustomerProduceServiceImpl implements CustomerProduceService {
   @Autowired
    private ProductInfoMapper productInfoMapper;

    @Autowired
    private DubboCacheManager dubboCacheManager;

    @Override
    public SingleLoanProductInfo getSingleLoanProductInfo() {
        return productInfoMapper.getSingleLoanProductInfo();
    }

    @Override
    public LightLoanProductInfo getLightLoanProductInfo() {
        return productInfoMapper.getLightLoanProductInfo();
    }

    @Override
    public List<ProductInfo> getProductList() {
        List<ProductInfo> productList = (List<ProductInfo>)dubboCacheManager.get(DubboCacheRegion.CHACHE__CUSTOMER_PRODUCES_LIST, HomePageConstant.CHACHE_HOME_PAGE_CUSTOMER_PRODUCES);
        if(productList == null ){
            productList = new ArrayList<ProductInfo>();
            productList.add(getSingleLoanProductInfo());
            productList.add(getLightLoanProductInfo());
            dubboCacheManager.put(DubboCacheRegion.CHACHE__CUSTOMER_PRODUCES_LIST,productList,HomePageConstant.CHACHE_HOME_PAGE_CUSTOMER_PRODUCES);
        }
        return productList;
    }
}
